package name.fowler.refactoring.simplestore;

import java.util.ArrayList;
import java.util.List;

public class Customer {
	private String m_Name;
	private List<Rental> m_Rentals = new ArrayList<Rental>();

	public Customer(String name) {
		m_Name = name;
	}

	public String getName() {
		return m_Name;
	}


	public void addRental(Rental arg){
		m_Rentals.add(arg);
	}

	public Statement Statement()
	{
		double totalAmount = 0;
		int frequentRenterPoints = 0;

        final List<RentalInfo> rentalInfos = new ArrayList<RentalInfo>();
        for(Rental each: m_Rentals) {
			double thisAmount = 0;
			
			// Determine amounts for each line
            final Movie movie = each.getMovie();
            switch(movie.getPriceCode()) {
				case Regular:
					thisAmount += 2;
					if (each.getDaysRented() > 2)
					{
						thisAmount += (each.getDaysRented() - 2) * 1.5;
					}
					break;
	
				case NewRelease:
					thisAmount += each.getDaysRented() * 3;
					break;
	
				case Childrens:
					thisAmount += 1.5;
					if (each.getDaysRented() > 3)
					{
						thisAmount = (each.getDaysRented() - 3) * 1.5;
					}
					break;
			}

			// Add frequent renter points
			frequentRenterPoints++;

			// Add bonus for a two-day new-release rental
			if ((movie.getPriceCode() == PriceCodes.NewRelease) && (each.getDaysRented() > 1))
			{
				frequentRenterPoints ++;
			}
            rentalInfos.add(new RentalInfo(movie, thisAmount));

			// Show figures for this rental
			totalAmount += thisAmount;
		}
        final Statement statement = new Statement(m_Name, rentalInfos, totalAmount, frequentRenterPoints);

        // Add footer lines
		return statement;
	}
}

